/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.vtc.app;

import java.io.IOException;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemCommandListener;
import javax.microedition.lcdui.StringItem;

/**
 *
 * @author Admin
 */
public class GameForm extends Form implements ItemCommandListener,CommandListener{
    
    private MainMidlet mid;
    private StringItem start, exit, options;
    private Command CMD_Start, CMD_Exit, CMD_Reset, CMD_Options, CMD_Ok;
    private Image logo;

    public GameForm(MainMidlet mid) {
        super("PROJECT MARIO ADVENTURE");
        this.mid = mid;
        this.creatForm();
    }
    private void creatForm() {
        try {
            this.logo = Image.createImage("/com/vtc/image/mario/mario_logo.png");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        this.append(logo);
        this.append("     ");
        this.start = new StringItem("", "Start", StringItem.BUTTON);
        this.exit = new StringItem("", "Exit", StringItem.BUTTON);
        this.options = new StringItem("", "Options", StringItem.BUTTON);
        this.CMD_Exit = new Command("Exit", Command.ITEM, 1);
        this.CMD_Start = new Command("Start", Command.ITEM, 1);
        this.CMD_Reset = new Command("Reset", Command.BACK, 1); 
        this.CMD_Options = new Command("Options", Command.ITEM, 1);
        this.CMD_Ok = new Command("Ok", Command.OK, 1);
        this.append(start);
        this.append(options);
        this.append(exit);
        this.start.setDefaultCommand(CMD_Start);
        this.start.setItemCommandListener(this);
        this.exit.setDefaultCommand(CMD_Exit);
        this.exit.setItemCommandListener(this);
        this.options.setDefaultCommand(CMD_Options);
        this.options.setItemCommandListener(this);
    }
    
    public void options(){
        Form formOptions = new Form("Options");
        formOptions.addCommand(CMD_Reset);
        formOptions.setCommandListener(this);
        formOptions.addCommand(CMD_Ok);
        formOptions.setCommandListener(this);
        Display.getDisplay(mid).setCurrent(formOptions);
    }
    
    public void showForm() {
        Display.getDisplay(mid).setCurrent(this);
    }

    public void commandAction(Command c, Item item) {
        if (c == CMD_Start) {
            GameCanvasProcess g = new GameCanvasProcess(true);
            g.addCommand(CMD_Reset);
            g.setCommandListener(this);
            g.startGame();
            Display.getDisplay(mid).setCurrent(g);
        }
        if (c == CMD_Exit) {
            this.mid.destroyApp(true);
        }
        if (c== CMD_Options) {
            this.options();
        }

    }

    public void commandAction(Command c, Displayable d) {
        if (c == CMD_Reset) {
            this.showForm();
        }
    }

    
    
}
